Skip to content

Serialize negLogConstant_ and pruned_ in HybridGaussianConditional - #2926

Open
sohailshk wants to merge 1 commit into
borglab:developfrom
sohailshk:fix/hybrid-conditional-serialize
Open

sohailshk wants to merge 1 commit into
borglab:developfrom
sohailshk:fix/hybrid-conditional-serialize

Conversation

@sohailshk

Copy link
Copy Markdown

HybridGaussianConditional::serialize() stores only its two base classes, so negLogConstant_ and pruned_ are lost in a round trip. The defaulted constructor leaves negLogConstant_ uninitialized, so a deserialized conditional reports an arbitrary value (0 or NaN when tested) instead of, for the two-component conditional in the existing serialization test, 0.225791. pruned_ comes back false. The wrong constant is returned by negLogConstant(), HybridConditional::negLogConstant() and HybridBayesNet::negLogConstant(). prune() adds negLogConstant_ back to the component scalars, so pruning a deserialized conditional also gives a conditional with negLogConstant() == 0. equals() compares neither member, which is why equalsObj/equalsXML/equalsBinary in the existing test pass.

Both members are now archived from class version 1 on (BOOST_CLASS_VERSION(gtsam::HybridGaussianConditional, 1)). Version 0 archives contain only the base classes and still load as before. Adding the members without the version check would make them fail with input stream error.

New tests in gtsam/hybrid/tests/testSerializationHybrid.cpp:

  • HybridSerialization.HybridGaussianConditionalConstantAndPruned round-trips a pruned two-component conditional through text, XML and binary archives and checks negLogConstant() and pruned(). It fails on develop with 6 failures (expected 0.225791 but was: 0.000000, deserialized->pruned()) and passes with the change.
  • HybridSerialization.HybridGaussianConditionalVersionZero writes the version 0 format through a legacy subclass, in the style of LegacyGaussianBayesTree in testSerializationLinear, and reads it back as a HybridGaussianConditional. It passes on develop and with this change, and fails with input stream error if the members are archived without the version check.

make check.hybrid (19 tests) passes.

serialize() only stored the two base classes, so a deserialized conditional came back with an uninitialized negLogConstant_ (0 or NaN in practice) and pruned_ reset to false. negLogConstant_ is returned by negLogConstant(), which HybridConditional::negLogConstant() and HybridBayesNet::negLogConstant() use, and prune() adds it back to the component scalars, so a conditional pruned after a round trip reports the wrong constant too. equals() compares neither member, which is why the existing serialization test passed.

Store both members from class version 1 on. Version 0 archives, which hold only the base classes, still load as before.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant